package com.menhai.personmanagement.controller;

import com.menhai.personmanagement.services.ISysRoleService;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import com.menhai.personmanagement.services.ISysUserService;
import com.menhai.personmanagement.entity.SysUser;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shikun
 * @since 2021-12-09
 */

@Slf4j
@RestController
@RequestMapping("/sys-user")
public class SysUserController {

     @Autowired
     private ISysUserService sysUserService;

     @Autowired
     private ISysRoleService sysRoleService;

     @RequestMapping("/selectAll")
     public Page<SysUser> selectAll(@Param("pagesize") int pagesize,@Param("size") int size){
          return sysUserService.selectAll(pagesize, size);
     }

     @RequestMapping("/getRole")
     public List getRole(){
          return sysRoleService.selectAll();
     }

     @RequestMapping("/addSysUser")
     public int addSysUser(SysUser sysUser){
          try {
               return sysUserService.addSysUser(sysUser);
          }catch (Exception e){
               return -1;
          }
     }

     @RequestMapping("/editSysUser")
     public int editSysUser(SysUser sysUser){
          return sysUserService.editSysUser(sysUser);
     }

     @RequestMapping("/findSysUser")// pagesize: pagesize.value,size: size.value
     public Page findSysUser(@Param("name") String name,@Param("zhen") String zhen,@Param("cun") String cun,@Param("pagesize") int pagesize,@Param("size") int size){
          return sysUserService.findSysUser(name,zhen,cun,pagesize,size);
     }

     @RequestMapping("/delSysUser")
     public int delSysUser(@Param("id") int id){
          return sysUserService.delSysUser(id);
     }

     @RequestMapping("/login")
     public Object login(@Param("account") String account,@Param("password") String password){
          List list =sysUserService.login(account, password);
          if(list.size() > 0){
               return list.get(0);
          }else{
               return null;
          }

     }

     @RequestMapping("/editPass")
     public int editPass(@Param("account") String account,@Param("pass") String pass){
          return sysUserService.editPass(account, pass);
     }
}
